<script src="http://libs.baidu.com/jquery/2.1.4/jquery.js"></script>
<script src="http://malsup.github.io/jquery.form.js"></script>

<form id="form1" action="showAllTime" >
范围开始日期：<input type="text" name="rangeTimeStart" value="2016-04-24"/> 范围结束日期 <input type="text" name="rangeTimeEnd" value="2016-04-30" /></br>
班级id：
<#list courseIds as value>
${value}<input type="radio" name="courseId" value="${value}" onclick="clickradio()" > | 
</#list>
</br>
教室id：
<#list classroomIds as value>
${value}<input type="radio" name="classroomId" value="${value}" onclick="clickradio()"> | 
</#list>
</br>
老师id：
<#list teacherIds as value>
${value}<input type="radio" name="teacherId" value="${value}" onclick="clickradio()"> | 
</#list>
</br>



新增课程 </br>
格式：2016-04-29 08:30:00   </br>

开始时间：<input type="text" name="startTimeStr" /> 结束时间 <input type="text" name="endTimeStr"  /></br>
<input type="button" value="保存" onclick="save()">
 	
<table id="table1">
<tr>
  <td width="33%" align="left" valign="top">开始时间</td>
    <td width="33%" valign="top">结束时间</div></td>
    <td width="33%" valign="top">信息</div></td>
   </tr>
<#list result as value>
<#if value.id??>
  <tr>
  
    <td>${value.startTime}</td>
    <td>${value.endTime}</td>
    <td>course:${value.courseId!" "}| classroom:${value.classroomId!" "}| tearcher:${value.teacherId!" "} </td>
    </tr>
    </#if>
 </#list>
 </table>
 
 </br>
 
 </form> </br>
 <script type="text/javascript">
 function save(){
	 $("#form1").ajaxSubmit(options2);
 }
 var options = {
	        success: callBackFunc  // post-submit callback</font> 
	    };
 
 var options2 = {
		 	url:'save',
	        success: callBackSave  // post-submit callback</font> 
	    };
	 
 function callBackFunc(response, statusText) {
	 
	    if (statusText == 'success') {
	        if(response.succese == true){
	        	refreshTable(response.result);
	        }
	    }else{
			alert("服务端错误！");
	     
	    }
	}
 
 function callBackSave(response, statusText) {
	 
	    if (statusText == 'success') {
	        if(response.succese == true){
	        	
	        	$("#form1").ajaxSubmit(options);
	        }else{
	        	alert("排课冲突！");
	        }
	    }else{
			alert("服务端错误！");
	  	}
	}
	  
function clickradio(){
	
	$("#form1").ajaxSubmit(options);
}
 function refreshTable(list){
	
	 $("#table1 tr:not(:first)").empty();
	 
	 $.each(list,function(name,value) {
		 
		 var str = "<tr> <td>"+formatDate(value.startTime)+"</td><td>"+formatDate(value.endTime)+"</td><td>course:"+value.courseId+" |classroom:"+value.classroomId+" |teacher:"+value.teacherId+"</td></tr>"
		 $("#table1 tr:last").after(str);
     });
	
 }
 
 function add0(m){return m<10?'0'+m:m }
 
 function formatDate(oldTime) { 
	 var newTime = new Date(oldTime)
	// var date = new Date(now);
	 var year=newTime.getFullYear(); 
	 var month=newTime.getMonth()+1; 
	 var date=newTime.getDate(); 
	 var hour=newTime.getHours(); 
	 var minute=newTime.getMinutes(); 
	 var second=newTime.getSeconds(); 
	 return year+"-"+add0(month)+"-"+add0(date)+" "+add0(hour)+":"+add0(minute)+":"+add0(second); 
	 } 

</script>  